﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YogaStudio.Data;
using YogaStudio.Data.Domain;

namespace YogaStudio.Service.BLL
{
    public class WaiverService : YogaStudio.Service.BLL.IWaiverService
    {
        private YogaStudioEntities db = new YogaStudioEntities();

        public WaiverRequest GetWaiverRequestById(int id)
        {
            return db.WaiverRequests.Single(w => w.Id == id);
        }

        public bool IsWaiverRequestIdValid(int id)
        {
            return db.WaiverRequests.Any(w => w.Id == id);
        }

        public void UpdateWaiverStatus(WaiverRequest waiver)
        {
            //db.Entry(waiver).State = EntityState.Modified;
            var wr = db.WaiverRequests.Single(w => w.Id == waiver.Id);
            wr.Status = waiver.Status;
            wr.ResponseReason = waiver.ResponseReason;
            db.SaveChanges();
        }

        public void CreateNewWaiver(WaiverRequest waiver)
        {
            var newWaiver = db.WaiverRequests.Add(waiver);
            db.SaveChanges();
        }

        public IEnumerable<WaiverRequest> GetAllWaiverRequest(int? customerId)
        {
            return db.WaiverRequests.Where(x => x.CustomerId == customerId);
        }

        public void Dispose(bool disposing)
        {
            if (disposing) db.Dispose();
        }

        public void Dispose()
        {
            Dispose(true);
        }
    }
}
